package com.ziroom.zifamily.zfcensor.logic;

import com.ziroom.zifamily.bussiness.common.enums.CensorStatusEnum;
import com.ziroom.zifamily.bussiness.common.pojo.dto.ManualCensorDTO;
import com.ziroom.zifamily.zfcensor.pojo.bo.CensorResultBO;
import com.ziroom.zifamily.zfcensor.mapper.entity.CensorContentEntity;
import com.ziroom.zifamily.zfcensor.service.CensorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;


/**
 * 
 * @author cuiyuhui
 */
@Component
public class CensorLogic {

    @Autowired
    private CensorService censorService;

    public boolean saveCensorContentFromFeed() {
        return true;
    }

    /**
     * 人审
     * @author cuiyuhui
     * @created
     * @param
     * @return
     */
    public boolean censorByManual(ManualCensorDTO manualCensorDto) {
        String censorIds = manualCensorDto.getCensorIds();
        List<String> censorIdList = Arrays.asList(censorIds.split(","));
        List<CensorResultBO> censorResultBoList = new ArrayList<>();
        censorIdList.stream().forEach( id -> {
            CensorResultBO censorResultDto = CensorResultBO.builder()
                    .censorId(Long.valueOf(id)).censorCode(manualCensorDto.getCensorCode())
                    .censorLevel(manualCensorDto.getCensorLevel().intValue())
                    .censorStatus(CensorStatusEnum.CENSOR_MANUAL.getCensorStatus())
                    .censorTime(new Date()).build();
            censorResultBoList.add(censorResultDto);

        });

        censorService.saveBatchCensorResult(censorResultBoList);
        return true;
    }

    /**
     * 机审
     * @author cuiyuhui
     * @created
     * @param
     * @return
     */
    public CensorContentEntity censorByAI() {

        // 同步存入数据库
        //判断数据库是新增还是修改

        //审核结果
        // 人审
        // 机审

        //保存审核结果
        return null;
    }
}
